package com.whmskj.xjlhsc.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.jitapi.JitController;
import com.whmskj.xjlhsc.jitapi.dto.CurClsInfoDto;
import com.whmskj.xjlhsc.jitapi.dto.Emp;
import com.whmskj.xjlhsc.utils.SCUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.whmskj.xjlhsc.entity.Backtoyourfeetandweigh;
import com.whmskj.xjlhsc.service.BacktoyourfeetandweighService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.List;

/**
 * @author lk
 * @since 2025-07-16 08:36:20
 */
@RestController
@RequestMapping("/api/backtoyourfeetandweigh")
@SaIgnore
public class BacktoyourfeetandweighController {

    @Autowired
    private BacktoyourfeetandweighService backtoyourfeetandweighService;
    @Autowired
    private JitController controller;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findPage")
    public ResponseEntity<Page<Backtoyourfeetandweigh>> findPage(@RequestBody Backtoyourfeetandweigh params) {
        Page<Backtoyourfeetandweigh> result = backtoyourfeetandweighService.findPage(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findList")
    @SaIgnore
    public Result findList(@RequestBody Backtoyourfeetandweigh params) {
        List<Backtoyourfeetandweigh> result = backtoyourfeetandweighService.findList(params);
        return Result.success(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<Backtoyourfeetandweigh> findById(@PathVariable("id") Long id) {
        Backtoyourfeetandweigh backtoyourfeetandweigh = backtoyourfeetandweighService.findById(id);
        return ResponseEntity.ok(backtoyourfeetandweigh);
    }

    /**
     * 新增
     *
     * @return
     */
    @PostMapping
    @SaIgnore
    public Result insert(@RequestBody List<Backtoyourfeetandweigh> backtoyourfeetandweighList) {
        Emp emp = SCUtil.getCurrentLoginEmp();
        CurClsInfoDto currentCls = ((CurClsInfoDto) controller.getCurrentCls().getData());
        backtoyourfeetandweighList.forEach(cur -> {
            cur.setStaff(emp.getEmpName() + emp.getEmpId());
            cur.setClasses((currentCls.getScclass()));
            cur.setClass1(currentCls.getTeamName());
            cur.setTimeOfWeight(new Date());
        });
        boolean result = backtoyourfeetandweighService.saveBatch(backtoyourfeetandweighList);
        return Result.success(result);
    }

    /**
     * 修改
     *
     * @param backtoyourfeetandweigh
     * @return
     */
    @PutMapping
    @SaIgnore
    public Result update(@RequestBody Backtoyourfeetandweigh backtoyourfeetandweigh) {
        boolean result = backtoyourfeetandweighService.update(backtoyourfeetandweigh);
        return Result.success(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @SaIgnore
    public Result delete(@PathVariable("id") Long id) {
        int result = backtoyourfeetandweighService.delete(id);
        return Result.success(result);
    }


}